# -*- coding: utf-8 -*-
"""
Created on Thu Jul 16 08:52:14 2020

@author: Administrator
"""
import math


class Height_DS():
    def __init__(self):
        self.X_global = None
        self.Y_global = None
        self.X_local = None 
        self.Y_local = None
        self.ave_height = None    # 对Y_local计算平均高度
        
    def cal_ave_height(self):
        self.ave_height = sum(self.Y_local)/len(self.Y_local)
        
class H_Speed_DS():
    def __init__(self):
        self.X_global = None
        self.Y_global = None
        self.X_wang = None 
        self.Y_wang = None
        self.X_fan = None 
        self.Y_fan = None
        self.ave_wang = None   
        self.ave_fan = None
        self.ave_global = None
        
    def cal_ave_wang(self):    # 往速度平均
        self.ave_wang = sum(self.Y_wang)/len(self.Y_wang)
        
    def cal_ave_fan(self):    # 返速度平均
        self.ave_fan = sum(self.Y_fan)/len(self.Y_fan)
        
    def cal_ave_global(self):    # 全局速度平均
        self.ave_global = (self.ave_wang + self.ave_fan) / 2
        
class V_Speed_DS():
    def __init__(self):
        self.X_global = None
        self.Y_global = None
        self.X_shang = None 
        self.Y_shang = None
        self.X_xia = None 
        self.Y_xia = None
        self.ave_shang = None   
        self.ave_xia = None
        
    def cal_ave_shang(self):    # 往速度平均
        self.ave_shang = sum(self.Y_shang)/len(self.Y_shang)
        
    def cal_ave_xia(self):    # 返速度平均
        self.ave_xia = sum(self.Y_xia)/len(self.Y_xia)
        
class H_Stop_DS():
    def __init__(self):
        self.X_global = None
        self.Y_global = None
        self.X_local = None
        self.Y_local = None
        self.max_diff = None
    
    def cal_max_diff(self):
        self.max_diff = max([abs(y) for y in self.Y_local])
        
class V_Stop_DS():
    def __init__(self):
        self.X_global = None
        self.Y_global = None
        self.X_local = None
        self.Y_local = None
        self.max_diff = None
    
    def cal_max_diff(self):
        self.max_diff = max([abs(y) for y in self.Y_local])
        
class FuYang_DS():
    def __init__(self):
        self.X_global = None
        self.Y_global = None
        self.X_local = None 
        self.Y_local = None
        self.ave_edge = None    # 对Y_local计算平均角度
        
    def cal_ave_edge(self):
        self.ave_edge = max(self.Y_local)
        
class GunZhuan_DS():
    def __init__(self):
        self.X_global = None
        self.Y_global = None
        self.X_local = None 
        self.Y_local = None
        self.ave_edge = None    # 对Y_local计算平均角度
        
    def cal_ave_edge(self):
        self.ave_edge = max(self.Y_local)
        
class PianHangJiao_DS():
    def __init__(self):
        self.X_global = None
        self.Y_global = None
        self.X_local = None 
        self.Y_local = None
        self.ave_edge = None    # 对Y_local计算平均角度
        
    def cal_ave_edge(self):
        self.ave_edge = max(self.Y_local)

'''航迹水平精度'''
class H_Trace_DS():
    def __init__(self):
        self.X_global = None
        self.Y_global = None
        self.X_local = None 
        self.Y_local = None
        self.max_diff = None
        
    def cal_max_diff(self):
        if len(self.X_local) == 0:
            return None
        x0 = self.X_local[0]
        y0 = self.Y_local[0]
        x1 = self.X_local[-1]
        y1 = self.Y_local[-1]
        if x1 == 0.0:
            return
        A = -y1/x1
        B = 1.0
        distances = []
        for i in range(0,len(self.X_local)):
            x = self.X_local[i]
            y = self.Y_local[i]
            disc = abs((A*x+B*y)/math.sqrt(A*A+B*B))
            distances.append(disc)
        # print(distances)
        self.max_diff = max(distances)
        
'''航迹水平精度（输入起终点经纬度）'''
class H_Trace2_DS():
    def __init__(self):
        self.X_global = None
        self.Y_global = None
        self.X_local = None 
        self.Y_local = None
        self.max_diff = None
        
    def cal_max_diff(self, OB, OA):
        if len(self.X_local) == 0:
            return None
        x0 = 0.0
        y0 = 0.0
        x1 = OB
        y1 = OA
        if x1 == 0.0:
            return
        A = -y1/x1
        B = 1.0
        distances = []
        for i in range(0,len(self.X_local)):
            x = self.X_local[i]
            y = self.Y_local[i]
            disc = abs((A*x+B*y)/math.sqrt(A*A+B*B))
            distances.append(disc)
        # print(distances)
        self.max_diff = max(distances)
  
'''航迹垂直精度'''
class V_Trace_DS():
    def __init__(self):
        self.X_global = None    # 时间
        self.Y_global = None    # 全局的时候显示高度
        self.X_local = None    # 时间
        self.Y_local = None    # 当前高度-预设飞行高度
        self.pre_height = None    # 预设飞行高度
        self.max_diff = None    # 最大航迹垂直误差
    
    def cal_max_diff(self):
        self.max_diff = max(self.Y_local)